# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=drozer
pkgver=2.4.4
pkgrel=11
groups=('blackarch' 'blackarch-mobile' 'blackarch-scanner' 'blackarch-fuzzer')
pkgdesc='A security testing framework for Android - Precompiled binary from official repository.'
arch=('any')
url='https://github.com/mwrlabs/drozer'
license=('BSD')
depends=('jre8-openjdk' 'python2' 'protobuf' 'python2-protobuf'
         'python2-pyopenssl' 'python2-twistedx' 'python2-service-identity')
options=(!strip)
source=("https://github.com/mwrlabs/drozer/releases/download/$pkgver/drozer_$pkgver.deb")
sha512sums=('39c4926477470914f646eebb22014527f70e194e8dcc2de3157ead1cf413df4c590f219ae8421476893deea05a0dc812cbba4245470bc109be301b9aabfaf418')

prepare() {
  bsdtar xfJ data.tar.xz
}

package() {
  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  cp -a usr/lib/python2.7/dist-packages/* "$pkgdir/usr/share/$pkgname/"

  install -Dm 644 usr/bin/drozer "$pkgdir/usr/share/$pkgname/_drozer.py"
  install -Dm 644 usr/bin/drozer-complete \
    "$pkgdir/usr/share/$pkgname/drozer-complete"
  install -Dm 644 usr/bin/drozer-repository \
    "$pkgdir/usr/share/$pkgname/drozer-repository"
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" \
    usr/share/doc/drozer/README.md
  install -Dm 644 usr/share/doc/drozer/LICENSE \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  install -Dm 644 etc/bash_completion.d/drozer \
    "$pkgdir/etc/bash_completion.d/$pkgname"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python2 _drozer.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"

  cat > "$pkgdir/usr/bin/drozer-complete" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python2 drozer-complete.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/drozer-complete"

cat > "$pkgdir/usr/bin/drozer-repository" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python2 drozer-repository.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/drozer-repository"
}

